package com.wendy;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

/**
 * @author Wendy
 * @Date 2021-7-1
 */
@Slf4j
@SpringBootApplication
@MapperScan("com.wendy.mapper")
public class BasicTemplateApplication extends SpringBootServletInitializer {

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(BasicTemplateApplication.class);
  }

  public static void main(String[] args) throws UnknownHostException {
    ConfigurableApplicationContext application = SpringApplication.run(BasicTemplateApplication.class, args);
    Environment env = application.getEnvironment();
    String ip = InetAddress.getLocalHost().getHostAddress();
    String port = env.getProperty("server.port");
    String path = Objects.requireNonNull(env.getProperty("server.servlet.context-path")).trim();
    log.info("\n----------------------------------------------------------\n" +
            "启动成功! 访问链接:\n" +
            "API🎁:      http://" + ip + ":" + port + path + "/\n" +
            "Swagger🎉:  http://localhost" + ":" + port + path + "/doc.html\n" +
            "----------------------------------------------------------");
  }

}
